<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>深度教育</title>
    <link rel="stylesheet" href="/web/resources/css/weui.css"/>
    <link rel="stylesheet" href="/web/resources/css/main.css"/>
    <script type="text/javascript" src="/web/resources/js/jquery-3.2.1.min.js"></script>
</head>
<body ontouchstart>

<div class="page" style="opacity: 255;">
    <div class="page__bd" style="height: 100%;">
        <div class="weui-tab">
            <div class="weui-navbar">
                <div class="weui-navbar__item weui-bar__item_on" style="background-color: #09BB07; color: white;">
                    登录页面
                </div>
            </div>
            <div class="weui-tab__panel">


<div style="text-align: center;">
    <input type="text" id="login_name" placeholder="登录名" /><br />
    <input type="password" id="login_pwd" placeholder="密码" /><br />
    <input type="button" id="btn_login" value="登录" />
</div>
<script type="text/javascript">
$(document).ready(function() {
    $("#btn_login").bind("click", login_user);
});

function login_user() {
    var login_name = $("#login_name").val();
    if ("" == login_name) {
        alert("登录名不能为空");
        $("#login_name").focus();
        return ;
    }
    var login_pwd = $("#login_pwd").val();
    if ("" == login_pwd) {
        alert("登录密码不能为空");
        $("#login_pwd").focus();
        return ;
    }
    var data = new Object();
    data.login_name = login_name;
    data.login_pwd = login_pwd;
    var req_url = "http://" + location.host + "/ajax?f=c_user&c=CUser&m=login_user";
    $.ajax({
        url: req_url,
        type: "POST",
        data: {
            "json_str": JSON.stringify(data)
        },
        dataType: "json",
        success: on_login_user_ok,
        error: on_login_user_error
    });
}
function on_login_user_ok(json) {
    if ("Ok" != json.status) {
        alert("用户登录失败！");
        return ;
    }
    localStorage.setItem("user_id", "" + json.user_id);
    localStorage.setItem("role_id", "" + json.role_id);
    localStorage.setItem("user_name", json.user_name);
    if (2 == json.role_id) {
        window.location.href = "http://" + location.host + "/web/pages?cmd=show_exercise"; // 学生进入练习页面
    }
}
function on_login_user_error(msg) {
    alert("用户登录失败：" + JSON.stringify(msg) + "！");
}
</script>
            </div>
        </div>
    </div>
</div>


</body>
</html>